package com.sskj.gocoin.mine;


import android.content.Context;
import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.m.bean.UserInfo;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.VerifyGuideActivity;
import com.sskj.gocoin.v.activity.VerifyJuniorActivity;
import com.sskj.gocoin.v.base.BaseActivity;
import com.sskj.lib.RConfig;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/04/02
 */
@Route(path = RConfig.MINE_VERIFY_HOME)
public class VerifyHomeActivity extends BaseActivity<VerifyHomePresenter> {

    @BindView(R2.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R2.id.line)
    View line;
    @BindView(R2.id.name)
    TextView name;
    @BindView(R2.id.card_num)
    TextView cardNum;
    @BindView(R2.id.junior_status)
    TextView juniorStatus;
    @BindView(R2.id.junior_verify)
    ConstraintLayout juniorVerify;
    @BindView(R2.id.high_tip)
    TextView highTip;
    @BindView(R2.id.high_status)
    TextView highStatus;
    @BindView(R2.id.high_verify)
    ConstraintLayout highVerify;

    @BindView(R2.id.llFirst)
    LinearLayout llFirst;
    @BindView(R2.id.llSecond)
    LinearLayout llSecond;


    private boolean verifyFirst;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_verify_home_n;
    }


    @Override
    public VerifyHomePresenter getPresenter() {
        return new VerifyHomePresenter();
    }


    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.request();
    }

    @Override
    protected void initView() {
        super.initView();
        toolbar.setLeftButtonOnClickLinster(v -> finish());
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, VerifyHomeActivity.class);
        context.startActivity(intent);
    }

    public void updateStatus(UserInfo userData) {
        if (userData != null) {
            setText(name, userData.getName());
            setText(cardNum, userData.getCard_id());
            switch (userData.getAuthentication()) {
                case 0://未认证
                    juniorStatus.setText(App.INSTANCE.getString(R.string.strSecurityCenterActivity222));
                    ClickUtil.click(llFirst, () -> {
                        VerifyJuniorActivity.start(this);
                    });
                    ClickUtil.click(llSecond, () -> {
                        ToastUtil.showShort(getString(R.string.first_verify));
                    });

                    highStatus.setText(App.INSTANCE.getString(R.string.fabimineJavaVerifyHomeActivity4));
                    ClickUtil.click(llSecond, () -> {
                        if (verifyFirst) {
                            VerifyGuideActivity.start(this);
                        } else {
                            ToastUtil.showShort(getString(R.string.first_verify));
                        }
                    });
                    break;
                case 1://已认证
                    verifyFirst = true;
                    juniorStatus.setText(App.INSTANCE.getString(R.string.strSecurityCenterActivity224));
                    highStatus.setText(App.INSTANCE.getString(R.string.fabimineJavaVerifyHomeActivity4));
                    ClickUtil.click(llSecond, () -> {
                        if (verifyFirst) {
                            VerifyGuideActivity.start(this);
                        } else {
                            ToastUtil.showShort(getString(R.string.first_verify));
                        }
                    });
                    break;
                case 2://审核中
                    highStatus.setText(App.INSTANCE.getString(R.string.fabimineJavaVerifyHomeActivity1));
                    llSecond.setClickable(false);
                    break;
                case 3://认证成功
                    highStatus.setText(App.INSTANCE.getString(R.string.fabimineJavaVerifyHomeActivity2));
                    ClickUtil.click(highStatus, () -> {
                        ARouter.getInstance().build(RConfig.MINE_VERIFY_RESULT)
                                .withBoolean("isSuccess", true)
                                .navigation();
                    });
                    break;
                case 4://认证失败
                    highStatus.setText(App.INSTANCE.getString(R.string.fabimineJavaVerifyHomeActivity3));
//                    ClickUtil.click(llSecond, () -> {
//                        if (verifyFirst) {
//                            VerifyGuideActivity.start(this);
//                        } else {
//                            ToastUtil.showShort(getString(R.string.first_verify));
//                        }
//                    });
                    ClickUtil.click(highStatus, () -> {
                        ARouter.getInstance().build(RConfig.MINE_VERIFY_RESULT)
                                .withBoolean("isSuccess", false)
                                .navigation();
                    });
                    break;
                default:
                    break;
            }

        }
    }
}
